package com.wanczy.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanczy.service.RoleMenuOpService;
import com.wanczy.service.impl.RoleMenuOpServiceImpl;
import com.wanczy.util.GetIDK;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@WebServlet("/servlet/RoleMenuUpdServlet")
public class RoleMenuUpdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		PrintWriter out = response.getWriter();// ȡ��out����
		int menuId = 0;
		int roleMenuId = 0;
		boolean flag2 = false;
		int roleId = Integer.parseInt(request.getParameter("roleId"));
		String values = request.getParameter("menuId");
		String value[] = values.split("\\.");
		RoleMenuOpService service = new RoleMenuOpServiceImpl();
		boolean flag = service.doDel(roleId);
		for (int i = 0; i < value.length; i++) {
			roleMenuId = GetIDK.getIdk();
			menuId = Integer.parseInt(value[i]);
			flag2 = service.doIns(roleMenuId, menuId, roleId);
		}
		JSONArray jsonA = new JSONArray();
		JSONObject jsonO = new JSONObject();
		jsonO.put("result", flag2);
		jsonA.add(jsonO);
		out.print(jsonA.toString());
		out.close();
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
